function Mapper0 () 
{
    this.init = function () 
    {
	var mem = new MEMORY();
	mem.init(0x10000);
	System.cpuMem=mem;
	this.buildMap();
    };

    this.buildMap = function ()
    {
	this.loadPRGROM();
	// this.loadCHRROM();
	// this.loadBattery();
	// this.cpu.resetIRQ();
    };

    this.loadPRGROM = function () 
    {
	var count = System.rom.romCount;
	if(count>1)
	{
	    this.loadRomBank(0,0x8000);
	    this.loadRomBank(1,0xC000);
	} else {
	    this.loadRomBank(0,0x8000);
	    this.loadRomBank(0,0xC000);
	};
    };
    

    this.loadRomBank = function (bank,addr)
    {
	var count = System.rom.romCount;
	var b = bank % count;
	arraycopy(System.rom.rom[b],0,System.cpuMem,addr,16384);
    };

    this.write = function (addr,val)
    {
	if(addr<0x2000) 
	{
	    System.cpuMem.write(addr & 0x7FF,val);
	} else if (addr>0x4017) {
	    System.cpuMem.write(addr,val);
	    // TODO save RAM
	} else if (addr > 0x2007 && addr < 0x4000 ) {
	    this.regWrite(0x2000 + (addr & 0x7 ),val);
	} else {
	    this.regWrite(addr,val);
	};
    };

    this.read = function (addr)
    {
	if(addr > 0x4017 ) 
	{
	    System.cpuMem.read(addr);
	} else if (addr >= 0x2000) {
	    this.regLoad(addr);
	} else {
	    System.cpuMem.read(addr & 0x7FF);
	};
    }
    ;

    this.regWrite = function (addr,val) 
    {
	// TODO
    };

    this.regRead = function (addr)
    {
	// TOOD
    }
    ;

};